package com.uduemc.biso.module.basic.service.common.controller;

import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.uduemc.biso.core.common.dto.CBMastermanageAppend;
import com.uduemc.biso.core.common.extities.CMasterUserData;
import com.uduemc.biso.core.extities.center.MasterUser;
import com.uduemc.biso.core.utils.RestResult;
import com.uduemc.biso.module.basic.service.common.service.CMasterUserService;

@RestController
@RequestMapping("/common/master-user")
public class CMasterUserController {

	private final static Logger logger = LoggerFactory.getLogger(CMasterUserController.class);

	@Autowired
	private CMasterUserService cMasterUserServiceImpl;

	/**
	 * 添加用户操作
	 * 
	 * @return
	 */
	@PostMapping("/user-append")
	public RestResult userAppend(@Valid @RequestBody CBMastermanageAppend cBMastermanageAppend) {
		logger.debug(cBMastermanageAppend.toString());
		MasterUser masterUser = cMasterUserServiceImpl.userAppend(cBMastermanageAppend);
		if (masterUser == null) {
			return RestResult.error();
		}
		return RestResult.ok(masterUser);
	}

	/**
	 * 通过参数过滤获取对应的列表数据
	 * 
	 * @param username
	 * @param numberKey
	 * @param status
	 * @param loginNode
	 * @param pageNumber
	 * @param pageSize
	 * @param orderByString
	 * @return
	 */
	@PostMapping("/user-infos")
	public RestResult userInfo(@RequestParam(value = "username", defaultValue = "") String username,
			@RequestParam(value = "numberKey", defaultValue = "") String numberKey,
			@RequestParam(value = "status", defaultValue = "-1") short status,
			@RequestParam(value = "loginNode", defaultValue = "-1") short loginNode,
			@RequestParam(value = "pageNumber", defaultValue = "1") int pageNumber,
			@RequestParam(value = "pageSize", defaultValue = "12") int pageSize,
			@RequestParam(value = "orderByString", defaultValue = "") String orderByString) {
		PageInfo<CMasterUserData> userInfo = cMasterUserServiceImpl.userInfo(username, numberKey, status, loginNode,
				pageNumber, pageSize, orderByString);
		return RestResult.ok(userInfo);
	}

}
